package top.whysu.edevice.system;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import top.whysu.edevice.emqx.DeviceMqttClient;
import top.whysu.edevice.utils.CronThreadPoolManager;

/**
 * 定时器：2分钟执行一次
 */
@Service("taskEvery2Min")
public class TaskEvery2Min {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskEvery2Min.class);

    @Scheduled(cron = "0 */2 * * * ?")
    public void taskEvery2min2() {
        CronThreadPoolManager.getExecutorService(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName()).execute(() -> {
            try {
                DeviceMqttClient.getInstance().reconnect();
            } catch (Exception e) {
                LOGGER.error("连接emq异常");
            }
        });
    }
}
